import sys
import os
import subprocess

# -----> Collect execute args
SOURCE_CODE_SUBMODULE:bool = False
for o in sys.argv:
    if o == "enable-SourceRunner": SOURCE_CODE_SUBMODULE = True

# -----> Collect execute logger mode
LOGGER_MODE:bool = False
for o in sys.argv:
    if o == "enable-Logger": LOGGER_MODE = True

# -----> Collect benchmark mode
BMARK_MODE:str
if len(sys.argv) < 2: print(f"(Log)[Error] Cannot read args(1), args list: ", end=""); print(sys.argv)
elif sys.argv[1] == "wifi": BMARK_MODE = "wifiBenchmark"
elif sys.argv[1] == "math": BMARK_MODE = "mathBenchmark"
elif sys.argv[1] == "mix": BMARK_MODE = "mixBenchmark"
else: print(f"(Log)[Error] Not found [<{sys.argv[1]}>] mode!")

# =========> Benchmark

# --------------> Wifi benchmark

# --------------> Math benchmark
if BMARK_MODE == "mathBenchmark":
    if SOURCE_CODE_SUBMODULE:
        from Submodule.MathBenchmark import *
        print(f"(Res)[Complete] Score is: {MathBenchmark.startCheck(disableLogger=LOGGER_MODE)}")

    if not SOURCE_CODE_SUBMODULE:
        if not os.path.exists("./CompileModule/MathBenchmark") and not os.path.isfile("./CompileModule/MathBenchmark"):
            print("(Log)[Error] Cannot read submodule, you need reinstall submodule!")
            sys.exit()

        print("(Log)[Working] Now benchmark with outside-kernel... ")
        BmarkPid = os.popen("./CompileModule/MathBenchmark 10 enable")
        print(BmarkPid.read())



# --------------> Mix benchmark